<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .basic {
        width: 400px;
        height: 100px;
        border: 1px solid black;
      }

      .happy {
        border: 4px solid red;
        background-color: rgba(255, 255, 0, 0.644);
        background: linear-gradient(30deg, yellow, pink, orange, yellow);
      }
      .sad {
        border: 4px dashed rgb(2, 197, 2);
        background-color: gray;
      }
      .normal {
        background-color: skyblue;
      }

      .atguigu1 {
        background-color: yellowgreen;
      }
      .atguigu2 {
        font-size: 30px;
        text-shadow: 2px 2px 10px red;
      }
      .atguigu3 {
        border-radius: 20px;
      }
    </style>
    <!--
       class样式和style样式的用法 
          class样式最常用，用字符串，字符串数组或者对象
      -->
    <script src="./js/vue.js"></script>
  </head>
  <body>
    <div id="root">
      <!-- 绑定class样式，字符串写法，适用于样式的类型不确定，需要动态指定 -->
      <div class="basic" :class="mood" @click="changeClass()">{{name}}</div>
      <!-- 绑定 class样式，数组写法，适用于样式个数和类型都不确定 -->
      <div class="basic" :class="classArr" @click="changeClass1()">
        {{name}}
      </div>
      <br />
      <!-- class样式使用对象，对象的属性要跟上面style里定义的名字对应-->
      <div class="basic" :class="classObj" @click="changeClass2()">
        {{name}}
      </div>
      <br />
      <!-- 使用style样式， 表达式使用对象，对象的属性要使用css样式自带的属性，使用驼峰命名-->
      <div class="basic" :style="styleObj">{{name}}</div>
    </div>
    <script type="text/javascript">
      Vue.config.productionTip = false
      const vm = new Vue({
        el: '#root',
        data: {
          name: '张三',
          mood: 'normal',
          classArr: ['atguigu1', 'atguigu2', 'atguigu3'],
          classObj: {
            atguigu1: false,
            atguigu2: false,
          },
          styleObj: {
            fontSize: '40px',
            color: 'red',
            backgroundColor: 'orange',
          },
        },
        methods: {
          changeClass() {
            const arr = ['atguigu1', 'atguigu2', 'atguigu3']
            const index = Math.floor(Math.random() * 3)
            this.mood = arr[index]
          },
          changeClass1() {
            if (this.classArr.length == 0) {
              this.classArr.push('atguigu1')
              this.classArr.push('atguigu2')
              this.classArr.push('atguigu3')
            }
            this.classArr.shift()
          },
          changeClass2() {
            console.log(this.classObj.atguigu1 == true)
            if (this.classObj.atguigu1 == false) {
              this.classObj.atguigu1 = true
            } else {
              this.classObj.atguigu1 = false
            }
            if (this.classObj.atguigu2 == false) {
              this.classObj.atguigu2 = true
            } else {
              this.classObj.atguigu2 = false
            }
          },
        },
      })
    </script>
  </body>
</html>
